import { queryTable } from '../services/dataInfo';
import { detailEntityApi,updateEntityApi } from '../../manager/service';
import { notification } from 'antd';

export default {
  namespace: 'table',
  state: {
    entityPageResult: { list: [] },
    projectApi: {},
  },

  effects: {
    * queryEntityPageList({ payload }, { call, put }) {
      const response = yield call(queryTable, payload);

      const entityPageResult = {
        list: response.data,
      };
      yield put({
        type: 'changeEntityPageList',
        payload: {
          code: response.code,
          entityPageResult
        },
      });
    },

    * getProjectApi({ payload,callback }, { call, put }) {
      const response = yield call(detailEntityApi, payload);

      if (response.code === 10000) {
        if (callback) callback(response.data);
        yield put({
          type: 'changeDetailEntity',
          payload: response.data,
        });
      }
    },

    * updateProject({ payload, callback }, { call }) {
      yield call(updateEntityApi, payload);
    },


  },

  reducers: {
    changeEntityPageList(state, { payload }) {
      return {
        ...state,
        entityPageResult: payload.entityPageResult,
      };
    },

    changeDetailEntity(state, { payload }) {
      return {
        ...state,
        projectApi: payload,
      };
    },


  },
};
